package com.sn.author.controller;

import com.sn.author.common.annotation.Advice;
import com.sn.author.common.annotation.IgnoreToken;
import com.sn.author.common.exception.BadRequestException;
import com.sn.author.domain.BaseResult;
import com.sn.author.domain.dto.AccountDTO;
import com.sn.author.domain.dto.ImportDTO;
import com.sn.author.domain.vo.*;
import com.sn.author.service.dao.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author xiaom
 * @Date 2020/9/15 21:58
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping(value = "/account")
@Api(tags = "账户管理/导入/导出")
public class AccountController {

    private final AccountService accountService;

    public AccountController(AccountService accountService) {
        this.accountService = accountService;
    }

    @PostMapping(value = "/getAccountList")
    @ApiOperation("获取抖音账户列表")
    public BaseResult<List<AccountDTO>> getAccountList(@RequestBody QueryAccountVo queryAccountVo){
        return accountService.getAccountList(queryAccountVo);
    }

    @PostMapping(value = "/deleteAccount")
    @ApiOperation("删除账号")
    public BaseResult<Boolean> deleteAccount(@RequestBody AccountVo accountVo){
        return BaseResult.success(accountService.delAccount(accountVo.getId()));
    }

    @GetMapping(value = "/exportAccount")
    @ApiOperation("导出账户")
    @Advice(need = false)
    public String exportAccount(){
        accountService.exportAccount();
        return "true";
    }

    @PostMapping(value = "/batchRegister")
    @ApiOperation("批量注册")
    public BaseResult<Boolean> batchRegister(@RequestBody NumberVo numberVo){
        Assert.isTrue((numberVo.getNum() != null && numberVo.getNum() >= 1),"注册数量不能小于1");
        return BaseResult.success(accountService.batchRegister(numberVo.getNum()));
    }

    @PostMapping(value = "/batchLogin")
    @ApiOperation("批量登录")
    public BaseResult<Boolean> batchLogin(@RequestBody @Valid BatchLoginVo batchLoginVo){
        return BaseResult.success(accountService.batchLogin(batchLoginVo));
    }

}
